package com.btpn.custody.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true)
@Table(name = "M_ACCOUNT")
@NamedQueries({
		@NamedQuery(name  = "Account.getUniqueAccount",
					query = "FROM Account a WHERE a.masterData.CIF.cifSid=:cif AND a.ACCOUNT=:account AND a.SUFIX=:sufix"),
		//ini			
		@NamedQuery(name  = "Account.findByBranchDateRange",
					query = "FROM Account a WHERE a.masterData.branch.id =:branchId AND a.ACCOUNT_OPEN BETWEEN :from AND :to"),
		@NamedQuery(name  = "Account.findCloseByBranchDateRange",
					query = "FROM Account a WHERE a.masterData.branch.id =:branchId AND a.ACCOUNT_CLOSE BETWEEN :from AND :to"),
	    //ini
		@NamedQuery(name  = "Account.findByAreaDateRange",
					query = "FROM Account a WHERE a.masterData.branch.area.id =:areaId AND a.ACCOUNT_OPEN BETWEEN :from AND :to ORDER BY a.masterData.branch.code"),
		@NamedQuery(name  = "Account.findCloseByAreaDateRange",
					query = "FROM Account a WHERE a.masterData.branch.area.id =:areaId AND a.ACCOUNT_CLOSE BETWEEN :from AND :to ORDER BY a.masterData.branch.code"),
		//ini
		@NamedQuery(name  = "Account.findByDateRange",
					query = "FROM Account a WHERE a.ACCOUNT_OPEN BETWEEN :from AND :to ORDER BY a.masterData.branch.code"),
		@NamedQuery(name  = "Account.findCloseByDateRange",
					query = "FROM Account a WHERE a.ACCOUNT_CLOSE BETWEEN :from AND :to ORDER BY a.masterData.branch.code"),

		@NamedQuery(name  = "Account.countForMasterSLA",
					query = "SELECT COUNT(a) FROM Account a " +
							"WHERE a.masterData.STATUS_SLA = :status " +
							"AND a.masterData.branch.area.id = :areaId " +
							"AND MONTH(a.ACCOUNT_OPEN) = :month " +
							"AND YEAR(a.ACCOUNT_OPEN) = :year"),
		@NamedQuery(name  = "Account.countForDetailSLA",
					query = "SELECT COUNT(a) FROM Account a " +
							"WHERE a.masterData.STATUS_SLA = :status " +
							"AND a.masterData.branch.id = :branchId " +
							"AND MONTH(a.ACCOUNT_OPEN) = :month " +
							"AND YEAR(a.ACCOUNT_OPEN) = :year"),
		@NamedQuery(name  = "Account.countForAllSLA",
					query = "SELECT COUNT(a) FROM Account a " +
							"WHERE a.masterData.STATUS_SLA = :status " +
							"AND MONTH(a.ACCOUNT_OPEN) = :month " +
								"AND YEAR(a.ACCOUNT_OPEN) = :year")
})
public class Account implements Serializable {

	/*=============================================== C O N S T A N T =========================================*/
	private static final long serialVersionUID = -6173313928377083961L;

	public static final String NQ__GET_UNIQUE_ACCOUNT 					= "Account.getUniqueAccount";

	public static final String NQ__FIND_BY_BRANCH_AND_DATE_RANGE		= "Account.findByBranchDateRange"; //ini
	public static final String NQ__FIND_CLOSE_BY_BRANCH_AND_DATE_RANGE	= "Account.findCloseByBranchDateRange";

	public static final String NQ__FIND_BY_AREA_AND_DATE_RANGE			= "Account.findByAreaDateRange"; //ini
	public static final String NQ__FIND_CLOSE_BY_AREA_AND_DATE_RANGE	= "Account.findCloseByAreaDateRange";

	public static final String NQ__FIND_BY_DATE_RANGE				= "Account.findByDateRange"; //ini
	public static final String NQ__FIND_CLOSE_BY_DATE_RANGE			= "Account.findCloseByDateRange";

	public static final String NQ__REPORT_02_MASTER_BY_AREA			= "Account.countForMasterSLA";

	public static final String NQ__REPORT_02_DETAIL_BY_BRANCH		= "Account.countForDetailSLA";

	public static final String NQ__REPORT_02_ALL					= "Account.countForAllSLA";

	/*=============================================== M E M B E R =============================================*/
// BASIC
	@Id
	@GeneratedValue
	@Column(name = "__ID")
	private Long id;

	@Column(name = "__CREATED_DATE")
	private Date createdDate = new Date();

	@Column(name = "__CREATED_BY")
	private String createdBy;

	@Column(name = "__LAST_UPDATED_DATE")
	private Date lastUpdatedDate = new Date();

	@Column(name = "__LAST_UPDATED_BY")
	private String lastUpdatedBy;

// ACCOUNT
	@Column(name = "ACCOUNT", columnDefinition="VARCHAR(20)")
	private String ACCOUNT;
	@Column(name = "BRANCH", columnDefinition="VARCHAR(4)")
	private String BRANCH;	// just desc, actually use a.masterData.branch.code
	@Column(name = "SUFIX", columnDefinition="VARCHAR(3)")
	private String SUFIX;

	@Column(name = "ACCOUNT_TYPE", columnDefinition="VARCHAR(4)")
	private String ACCOUNT_TYPE;

	// casa/dep
	@Column(name = "REKENING_TYPE", columnDefinition="VARCHAR(4)")
	private String REKENING_TYPE;

	@Column(name = "ACCOUNT_OPEN")
	private Date ACCOUNT_OPEN;

	@Column(name = "ACCOUNT_CLOSE")
	private Date ACCOUNT_CLOSE;

	// from Damaro
	@Column(name = "CREATED_USER_ID", columnDefinition="CHAR(4)")
	private String CREATED_USER_ID;

	@ManyToOne
	@JoinColumn(name="MD_ID")
	private MasterData masterData;

	/*=============================================== G E T T E R   &   S E T T E R ===========================*/
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public Date getLastUpdatedDate() {
		return lastUpdatedDate;
	}

	public void setLastUpdatedDate(Date lastUpdatedDate) {
		this.lastUpdatedDate = lastUpdatedDate;
	}

	public String getLastUpdatedBy() {
		return lastUpdatedBy;
	}

	public void setLastUpdatedBy(String lastUpdatedBy) {
		this.lastUpdatedBy = lastUpdatedBy;
	}

	public String getACCOUNT() {
		return ACCOUNT;
	}

	public void setACCOUNT(String aCCOUNT) {
		ACCOUNT = aCCOUNT;
	}

	public String getACCOUNT_TYPE() {
		return ACCOUNT_TYPE;
	}

	public void setACCOUNT_TYPE(String aCCOUNT_TYPE) {
		ACCOUNT_TYPE = aCCOUNT_TYPE;
	}

	public String getREKENING_TYPE() {
		return REKENING_TYPE;
	}

	public void setREKENING_TYPE(String rEKENING_TYPE) {
		REKENING_TYPE = rEKENING_TYPE;
	}

	public Date getACCOUNT_OPEN() {
		return ACCOUNT_OPEN;
	}

	public void setACCOUNT_OPEN(Date aCCOUNT_OPEN) {
		ACCOUNT_OPEN = aCCOUNT_OPEN;
	}

	public String getCREATED_USER_ID() {
		return CREATED_USER_ID;
	}

	public void setCREATED_USER_ID(String cREATED_USER_ID) {
		CREATED_USER_ID = cREATED_USER_ID;
	}

	public MasterData getMasterData() {
		return masterData;
	}

	public void setMasterData(MasterData masterData) {
		this.masterData = masterData;
	}

	public Date getACCOUNT_CLOSE() {
		return ACCOUNT_CLOSE;
	}

	public void setACCOUNT_CLOSE(Date aCCOUNT_CLOSE) {
		ACCOUNT_CLOSE = aCCOUNT_CLOSE;
	}

	public String getBRANCH() {
		return BRANCH;
	}

	public void setBRANCH(String bRANCH) {
		BRANCH = bRANCH;
	}

	public String getSUFIX() {
		return SUFIX;
	}

	public void setSUFIX(String sUFIX) {
		SUFIX = sUFIX;
	}
}
